Skip to content

test: add unit tests for IsClusterReady and ClusterAccessCredentialChanged#7677

Open
Goutham-Annem wants to merge 1 commit into
karmada-io:masterfrom
Goutham-Annem:test/cluster-util-missing-tests
Open

test: add unit tests for IsClusterReady and ClusterAccessCredentialChanged#7677
Goutham-Annem wants to merge 1 commit into
karmada-io:masterfrom
Goutham-Annem:test/cluster-util-missing-tests

Conversation

@Goutham-Annem

Copy link
Copy Markdown

What type of PR is this?

/kind feature

What this PR does / why we need it:

Two functions in pkg/util/cluster.go lacked unit test coverage. This PR adds tests for:

  • IsClusterReady — covers no conditions, Ready=True, Ready=False, Ready=Unknown, and the case where the Ready condition is absent but other conditions are present
  • ClusterAccessCredentialChanged — covers identical specs (returns false), and each field that triggers a change: APIEndpoint, InsecureSkipTLSVerification, ProxyURL, ProxyHeader, plus the empty-specs base case

Which issue(s) this PR fixes:

Fixes #7676

Special notes for your reviewer:

All new tests follow the table-driven pattern used throughout cluster_test.go.

Does this PR introduce a user-facing change?:

NONE

…anged

Add unit tests for two functions in pkg/util/cluster.go that lacked
coverage:
- IsClusterReady: covers no conditions, Ready=True, Ready=False,
  Ready=Unknown, and Ready condition absent
- ClusterAccessCredentialChanged: covers identical specs (no change),
  and each changed field: APIEndpoint, InsecureSkipTLSVerification,
  ProxyURL, ProxyHeader, plus the empty-specs base case

Fixes karmada-io#7676

Signed-off-by: Goutham Annem <annem.usedu@gmail.com>
Copilot AI review requested due to automatic review settings June 27, 2026 18:10
@karmada-bot karmada-bot added the kind/feature Categorizes issue or PR as related to a new feature. label Jun 27, 2026
@karmada-bot

Copy link
Copy Markdown
Contributor

Invalid commit message issues detected

Invalid commit messages

Keywords which can automatically close issues and hashtag(#) mentions are not allowed.

  • 253c0f4 test: add unit tests for IsClusterReady and ClusterAccessCredentialChanged

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@karmada-bot karmada-bot added the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Jun 27, 2026
@karmada-bot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign chaunceyjiang for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request improves the reliability of the codebase by introducing unit tests for previously uncovered utility functions in pkg/util/cluster.go. These tests validate cluster readiness conditions and credential change detection logic, ensuring robust behavior across different input states.

Highlights

  • Test Coverage: Added comprehensive unit tests for IsClusterReady and ClusterAccessCredentialChanged functions.
  • Testing Methodology: Implemented table-driven tests to ensure consistent and readable test cases for various edge scenarios.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@karmada-bot karmada-bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jun 27, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces unit tests for IsClusterReady and ClusterAccessCredentialChanged in pkg/util/cluster_test.go. The review feedback suggests adding a test case to ensure changes to non-credential fields do not trigger false positives. Additionally, it points out that the underlying ClusterAccessCredentialChanged function does not check for changes in SecretRef or ImpersonatorSecretRef, which could lead to undetected credential updates.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread pkg/util/cluster_test.go
Comment on lines +664 to +669
{
name: "empty specs — no change",
newSpec: clusterv1alpha1.ClusterSpec{},
oldSpec: clusterv1alpha1.ClusterSpec{},
want: false,
},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

It is important to verify that changes to non-credential fields (such as SyncMode, Provider, Region, etc.) do not trigger a credential change detection. Adding a test case for this ensures that ClusterAccessCredentialChanged only returns true for actual credential-related changes.

		{
			name:    "empty specs — no change",
			newSpec: clusterv1alpha1.ClusterSpec{},
			oldSpec: clusterv1alpha1.ClusterSpec{},
			want:    false,
		},
		{
			name:    "non-credential fields changed — no change",
			newSpec: clusterv1alpha1.ClusterSpec{
				APIEndpoint: "https://k8s.example.com",
				SyncMode:    clusterv1alpha1.Push,
			},
			oldSpec: clusterv1alpha1.ClusterSpec{
				APIEndpoint: "https://k8s.example.com",
				SyncMode:    clusterv1alpha1.Pull,
			},
			want:    false,
		},

Comment thread pkg/util/cluster_test.go
}
}

func TestClusterAccessCredentialChanged(t *testing.T) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The ClusterAccessCredentialChanged function in pkg/util/cluster.go currently does not check if SecretRef or ImpersonatorSecretRef has changed. If a user updates these references to point to a different secret, the function will incorrectly return false (assuming other fields like APIEndpoint are identical). This means credential changes might not be detected.

Consider updating ClusterAccessCredentialChanged in pkg/util/cluster.go to include these fields, and then add corresponding test cases here to verify that behavior.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds missing unit coverage for cluster readiness detection and access-credential change detection utilities, improving confidence in cluster lifecycle and controller behaviors that depend on these helpers.

Changes:

  • Add table-driven unit tests for IsClusterReady across key condition permutations.
  • Add table-driven unit tests for ClusterAccessCredentialChanged across each relevant field change scenario.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/util/cluster_test.go
Comment on lines +605 to +608
{
Type: "SomeOtherCondition",
Status: metav1.ConditionTrue,
},
Comment thread pkg/util/cluster_test.go
Comment on lines +664 to +669
{
name: "empty specs — no change",
newSpec: clusterv1alpha1.ClusterSpec{},
oldSpec: clusterv1alpha1.ClusterSpec{},
want: false,
},
@codecov-commenter

codecov-commenter commented Jun 27, 2026

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 42.07%. Comparing base (56d5d87) to head (253c0f4).
⚠️ Report is 16 commits behind head on master.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7677      +/-   ##
==========================================
+ Coverage   42.06%   42.07%   +0.01%     
==========================================
  Files         879      879              
  Lines       54831    54831              
==========================================
+ Hits        23063    23072       +9     
+ Misses      30023    30014       -9     
  Partials     1745     1745              
Flag Coverage Δ
unittests 42.07% <ø> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. kind/feature Categorizes issue or PR as related to a new feature. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: add unit tests for IsClusterReady and ClusterAccessCredentialChanged in pkg/util/cluster.go

4 participants